package com.huawei.boss.http;

import java.io.StringBufferInputStream;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class SoapProxyServletRequestWrapper extends HttpServletRequestWrapper {
    private String soapMessage = null;

    public SoapProxyServletRequestWrapper(HttpServletRequest request) {
        super(request);
    }

    public void setSoapMessage(String soapMessage) {
        this.soapMessage = soapMessage;
    }

    public ServletInputStream getInputStream() throws java.lang.IllegalStateException, java.io.IOException {
        if (soapMessage == null)
            return null;
        StringBufferInputStream in = null;
        try {
            in = new StringBufferInputStream(soapMessage);
        } catch (Exception ex) {
        }
        return new BufferedServletInputStream(in);

    }
    
    private static class BufferedServletInputStream extends ServletInputStream {
        private StringBufferInputStream bais;

        public BufferedServletInputStream(StringBufferInputStream bais) {
            this.bais = bais;
        }

        public int available() {
            return this.bais.available();
        }

        public int read() {
            return this.bais.read();
        }

        public int read(byte[] buf, int off, int len) {
            return this.bais.read(buf, off, len);
        }
    }
}

